package com.zufe.ui;

import java.util.Random;

public class CodeUtil {
    public static String getCode() {
        char[] letters = new char[52];
        char[] codes = new char[5];
        for (int i = 0; i < letters.length; i++) {
            if (i < 26) {
                letters[i] = (char) ('A' + i);
            } else {
                letters[i] = (char) ('a' + i - 26);
            }
        }
        Random r = new Random();
        for (int i = 0; i < 4; i++) {
            codes[i] = letters[r.nextInt(52)];
        }
        codes[4] = (char) (r.nextInt(10) + '0');

        int index = r.nextInt(5);
        char temp = codes[4];
        codes[4] = codes[index];
        codes[index] = temp;
        return new String(codes);
    }
}
